<?php
include_once("sql_connect.php");
include_once("msg_redirect.php");
?>

<?php
$my_sql = mysql_query("select MAX(u_no) from user_info", $connection);	/*查询最大的用户编号*/
$sum = mysql_fetch_array($my_sql);	/*将最大用户编号赋值给$sum*/
/*将用户的注册信息插入数据表中*/
if($_POST[regist] =="yes"){
	$u_no = $sum[0] + 1;
	//$u_name = $_POST[regist_nickname];
	$u_email = $_POST[email_reg];
	$u_passwd = md5($_POST[password_reg]);	
	
	/*查询用户名与邮箱是否已经被注册*/
	//$my_sql = mysql_query("select * from user_info where u_passwd = '$u_passwd'", $connection);
	$my_sql1 = mysql_query("select * from user_info where u_email = '$u_email'", $connection);
	/*if(mysql_num_rows($my_sql)){
		msg_redirect("该昵称已被注册，请重新填写！","index.php");
	}*/
	 if(mysql_num_rows($my_sql1)){
		msg_redirect("该邮箱已被注册，请使用已经申请过的账号登陆！", "index.php");
	}
	/*插入数据*/
	else {
		/*插入用户注册信息到user_info表*/
		mysql_query("insert into user_info values
		($u_no,'$u_email','$u_passwd','$u_email','','')", $connection)
		or die(mysql_error());
		
		/*初始化concerns表*/
		$concerns_sql = mysql_query("select MAX(no) from concerns");
		$concerns_no = mysql_fetch_array($concerns_sql);
		$concerns_id = $concerns_no [0] + 1;
		mysql_query("insert into concerns value($concerns_id,$u_no,$u_no,0,0)") 
		or die(mysql_error());		
	    
		
		/*初始化user_detail表*/
		mysql_query("insert into user_detail value($u_no,'','','','','','','','')") 
		or die(mysql_error());
		
		/*查询head表的最大编号*/
		$my_sql = mysql_query("select MAX(h_id) from head");
		$head_sum = mysql_fetch_array($my_sql);
		$h_id = $head_sum[0] + 1;
		/*初始化head表
		mysql_query("insert into head value($h_id,'','',$u_no)") 
		or die(mysql_error());*/
		msg_redirect("成功注册TTU！", "index.php");
	}
}
mysql_close($connection);
?>
